package com.jtx.miaoah2.Controller;

import com.jtx.miaoah2.Common.BaseResponse;
import com.jtx.miaoah2.Common.RabbitMqConstants;
import com.jtx.miaoah2.Model.order.DTO.CreateOrderDto;
import com.jtx.miaoah2.Model.order.DTO.PayCompletedDTO;
import com.jtx.miaoah2.Service.SkOrderService;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 季台星
 * @Date 2023 07 23 19 43
 * 秒杀活动中购买商品相关接口
 */
@RestController
@RequestMapping("/api/v1/buy")
public class BookingController {
    @Autowired
    private SkOrderService skOrderService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 抢购资格获取(预下单接口)
     */
    @PostMapping("/panicBuy")
    public BaseResponse snappedGoods(@RequestBody CreateOrderDto createOrderDto){
        return skOrderService.panicBuy(createOrderDto);
    }


    @GetMapping("/sendMsg")
    public BaseResponse sendMsg(){
        rabbitTemplate.convertAndSend(RabbitMqConstants.SNAPPED_EXCHANGE,
                RabbitMqConstants.SNAPPED_ROUTEING_KEY,
                "hello,word");
        return BaseResponse.success();
    }

    /**
     * 支付接口
     */
    @PostMapping("/pay")
    public BaseResponse payCompleted(@RequestBody PayCompletedDTO payCompletedDTO){
        return skOrderService.payComplete(payCompletedDTO);
    }


}
